Send contact form email via Cloudflare send_email binding - #5
Merged
Conversation
Replaces the stalled Gmail API/OAuth2 approach with Cloudflare's native Email Routing send_email binding (legacy EmailMessage/mimetext API). This account doesn't have the Workers Paid plan the newer Email Sending product requires, so the classic binding is used instead, restricted to an already-verified destination address — free, and no third-party credentials needed. Verified end to end with a live send via a temporary local wrangler dev session in remote mode. Adds route-level unit tests for the full POST /api/contact pipeline (validation, reCAPTCHA, rate limit, send) against mocked bindings, plus cloudflare:email/cloudflare:workers test shims since those are Workers-runtime-only virtual modules. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
send_emailWorker binding (legacyEmailMessage/mimetextAPI)2036 UnauthorizedAPI response), so the classic binding is used instead — free on the current plandestination_addressto a single, already-verified destination address (blindtechmage+jwauthier@gmail.com), so no sending-domain SPF/DKIM onboarding is needed and no third-party (Google OAuth) credentials are involved in deliverywrangler dev --remotesession (torn down afterward, not part of this PR)Test plan
npm run typecheckpassesnpm run lint:jspassesnpm run test:unitpasses (26 tests) — includes newtests/unit/contact/email.test.ts(MIME message construction) andtests/unit/contact/route.test.ts(fullPOST /api/contactpipeline against mockedEMAIL/RATE_LIMITbindings and mockedfetchfor reCAPTCHA)npm run buildsucceeds; confirmedsend_emailbinding andnodejs_compatflag appear in the generateddist/server/wrangler.jsonNot yet functional in production
Still requires manual provisioning outside this repo: the
RATE_LIMITKV namespace and a reCAPTCHA site/secret key pair. Seedocs/SECURITY.mdOpen Items.🤖 Generated with Claude Code